package util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;

/**
 * This custom formatter formats entries in the log record.
 * It appends the following header: <Logging Level>: <yyyy-MM-dd-HH:mm:ss-sss>.
 */
public class LogFormatter extends Formatter {

	//RBB
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss-sss");
	Level level;
	
	public LogFormatter() {
	}

	// This method is called for every log records
	
	/**
	 * Format the LogRecord.
	 */
    public String format(LogRecord rec) {
        StringBuffer buf = new StringBuffer(1000);
        if (rec.getLevel().intValue() >= Level.WARNING.intValue()) {
        	buf.append("**");
        }
        buf.append(rec.getLevel().toString());
        buf.append(": ");
        Date date = new Date();
        buf.append(dateFormat.format(new Date(rec.getMillis())));
        buf.append(" (");
        buf.append(rec.getMillis());
        buf.append("ms)\n");
        buf.append(formatMessage(rec));
        buf.append('\n');
        return buf.toString();
    }

    // This method is called just after the handler using this
    // formatter is created
    public String getHead(Handler handler) {
//        return "<HTML><HEAD>"+(new Date())+"</HEAD><BODY><PRE>\n";
    	return "";
    }

    // This method is called just after the handler using this
    // formatter is closed
    public String getTail(Handler handler) {
//        return "</PRE></BODY></HTML>\n";
        return "";
    }
}